<template>
  <view class="complaints-container">
    <view class="complaints-list">
      <view v-for="(complaint, index) in complaints" :key="index" class="complaint-item">
        <view class="complaint-header">
          <text class="complaint-time">{{ complaint.submitTime }}</text>
          <text :class="['complaint-status', complaint.status]">{{ getStatusText(complaint.status) }}</text>
        </view>
        <view class="complaint-content" @click="viewDetail(complaint.id)">
          <text class="complaint-title">{{ complaint.title }}</text>
          <text class="complaint-desc">{{ complaint.description }}</text>
          <view v-if="complaint.reply" class="complaint-reply">回复: {{ complaint.reply }}</view>
        </view>
      </view>
    </view>
    
    <view v-if="complaints.length === 0" class="empty-state">
      <text>暂无投诉记录</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      complaints: [
        {
          id: 1,
          title: '电梯故障投诉',
          description: '5号楼电梯已经坏了三天，请尽快修理',
          submitTime: '2025-02-15 14:30',
          status: 'processing',
          reply: ''
        },
        {
          id: 2,
          title: '噪音扰民投诉',
          description: '楼上装修噪音过大，影响休息',
          submitTime: '2023-06-10 09:15',
          status: 'resolved',
          reply: '已联系业主，装修将在规定时间内进行'
        }
      ]
    }
  },
  
  onLoad() {
    // this.fetchComplaintHistory()
  },
  
  methods: {
    async fetchComplaintHistory() {
      try {
        // 从后端获取投诉历史数据
        const res = await this.$api.getComplaintHistory()
        this.complaints = res.data
      } catch (error) {
        uni.showToast({
          title: '获取数据失败',
          icon: 'none'
        })
      }
    },
    
    getStatusText(status) {
      const statusMap = {
        'pending': '待处理',
        'processing': '处理中',
        'resolved': '已解决',
        'rejected': '已驳回'
      }
      return statusMap[status] || status
    },
    
    viewDetail(id) {
      uni.navigateTo({
        url: `/pages/my/complaint-detail?id=${id}`
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.complaints-container {
  padding: 20rpx;
  
  .complaints-list {
    .complaint-item {
      background: #fff;
      border-radius: 12rpx;
      padding: 20rpx;
      margin-bottom: 20rpx;
      
      .complaint-header {
        display: flex;
        justify-content: space-between;
        margin-bottom: 16rpx;
        
        .complaint-time {
          color: #999;
          font-size: 24rpx;
        }
        
        .complaint-status {
          font-size: 24rpx;
          
          &.pending { color: #ff9900; }
          &.processing { color: #2979ff; }
          &.resolved { color: #19be6b; }
          &.rejected { color: #fa3534; }
        }
      }
      
      .complaint-content {
        .complaint-title {
          font-size: 28rpx;
          font-weight: bold;
          margin-bottom: 8rpx;
        }
        
        .complaint-desc {
          font-size: 26rpx;
          color: #666;
          margin-bottom: 8rpx;
        }
        
        .complaint-reply {
          font-size: 26rpx;
          color: #2979ff;
          background-color: rgba(41, 121, 255, 0.1);
          padding: 10rpx;
          border-radius: 8rpx;
        }
      }
    }
  }
  
  .empty-state {
    text-align: center;
    padding: 60rpx 0;
    color: #999;
  }
}
</style>
